package sensors;

import flixel.addons.tile.FlxTilemapExt;
import level.Tiles;

class AndSensor extends DependentSensor
{
	public function new(X: Float, Y: Float, map: FlxTilemapExt){
 		super(X, Y, map);
 		BasicSensor._sensors.get("AndSensor").add(this);		
 		deactivate();
	}

	override public function update()
	{
		super.update();
		if(_parents.length == 0) return;
		
		for(i in 0..._parents.length)
		{
			if(!_parents[i].isActive)
			{
				deactivate();
				return;
			}
		}
		activate();
	}

	override public function activate()
	{
		_map.setTileByIndex(_iTile, Tiles.AND_SENSOR_ON, true);
		super.activate();
	}

	override public function deactivate()
	{
		_map.setTileByIndex(_iTile, Tiles.AND_SENSOR_OFF, true);
		super.deactivate();
	}
}